package com.mytime.entity;

import org.json.JSONException;
import org.json.JSONObject;

public class Local {

	private String name;
	private String street;
	private String number;
	private String district;
	private String city;
	private String state;
	private String country;
	private String zipcode;
	private String coordinates;

	/**
	 * No parameter Constructor.
	 * **/
	public Local() {
		
	}

	/**
	 * Constructor.
	 * It receives a JSONObject that contains the information to create the object. 
	 * **/
	public Local(JSONObject obj) {
		this.name = getStringFromJSON(obj, "name");
		this.street = getStringFromJSON(obj, "street");
		this.number = getStringFromJSON(obj, "number");
		this.district = getStringFromJSON(obj, "district");
		this.city = getStringFromJSON(obj, "city");
		this.state = getStringFromJSON(obj, "state");
		this.country = getStringFromJSON(obj, "country");
		this.zipcode = getStringFromJSON(obj, "zipcode");
		this.coordinates = getStringFromJSON(obj, "coordinates");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	public String getCoordinates() {
		return coordinates;
	}

	public void setCoordinates(String coordinates) {
		this.coordinates = coordinates;
	}
	
	private String getStringFromJSON(JSONObject obj, String key) {
		if (obj.has(key)) {
			try {
				return obj.getString(key);
			} catch (JSONException e) {
				e.printStackTrace();
			} 
		}
		return null;
	}
}
